package com.cindata

import com.cindata.dictionary.*

class AbnormalMortgageBatch 
{

    String name
    String disposeMethod    //处置方式：债券转让、所有权转让
    Workflow workflow

    // AbnormalMortgageBatchStage stage
    // String status = "Pending"
    String descriptionOfFailure
    //失败原因说明

    Date createdDate = new Date()
    Date modifiedDate = new Date()
    User user
    User createBy
    User modifyBy

    Date startTime
    Date endTime

    Date actualStartTime
    Date actualEndTime

    Department disposalDepartment
    User disposalUser
    String description

    String type
    // 资产类型

    Boolean isInWorkflow = false

    Account account
    // 所属银行机构

    static hasMany = [mortgages: BatchMortgage]
    static mapping = {
        autowire true
    }
    static constraints = 
    {
      name maxSize: 30, nullable: false, blank: false, comment: '资产包名称'
      disposeMethod maxSize: 10, nullable: false, blank: false, comment: '处置方式'
      disposeMethod inList: ['债权转让', '所有权转让']
      // stage nullable: true, blank: true, comment: '处置阶段'
      // status maxSize: 10, nullable: true, blank: true
      // status inList: ["Pending", "Failed", "Completed"]
      workflow nullable: true, blank: true
      descriptionOfFailure  maxSize: 200, nullable: true, blank: true

      createdDate nullable: true, blank: true
      modifiedDate nullable: true, blank: true
      user nullable: true, blank: true
      createBy nullable: true, blank: true
      modifyBy nullable: true, blank: true

      startTime nullable: true, blank: true
      endTime nullable: true, blank: true
      actualStartTime nullable: true, blank: true
      actualEndTime nullable: true, blank: true

      disposalDepartment nullable: true, blank: true
      disposalUser nullable: true, blank: true
      description maxSize: 200, nullable: true, blank: true
      isInWorkflow nullable: true, blank: true

      type maxSize: 30, nullable: true, blank: true
      account maxSize: 30, nullable: true, blank: true
    }

    def springSecurityService

    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        def user = User.findByUsername(username)
        createBy = user
        account = user?.account
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }

}
